import { Component, OnInit } from '@angular/core';
import { ProductService, Product } from '../shard/product.service';
import { FormControl } from '@angular/forms';
import 'rxjs/Rx'

@Component({
  selector: 'app-products',
  templateUrl: './products.component.html',
  styleUrls: ['./products.component.css']
})
export class ProductsComponent implements OnInit {

  //private products: Array<Product>; // 定义一个私有属性products,是一个数组
  private products : Product[];

  private keyWord:string;
  private titleFilter:FormControl = new FormControl();

  private imgUrl = "http://via.placeholder.com/320x150";  // 属性绑定 
  
  constructor(private productService : ProductService) {
    this.titleFilter.valueChanges
    .debounceTime(500)
    .subscribe(
      value => this.keyWord = value
    );
   }

  ngOnInit() {
      this.products = this.productService.getProducts();
  }

}


